<template>
  <div class="nav-wrapper">
    <img @click="$router.push('/')" src="../assets/images/logo.png" alt="">
    <div class="menu" >
      <template v-if="!isPhone">
        <div class="item" @click="$router.push('/mfi')">
          <p>Metapool</p>
        </div>
        <div class="item" @click="$router.push('/undeveloped')">
          <p>{{$t('user.M_home_govern')}}</p>
        </div>
        <div class="item"  @click="$router.push('/rule')">
          <p>{{$t('user.M_home_rules')}}</p>
        </div>
      </template>
      <div class="item">
        <a-dropdown v-model="lanChecked" :trigger="['click']" :overlayStyle="{position: 'fixed'}">
              <div class="language">
                <div><img :src="langList[activeLang].src" alt="">
                {{langList[activeLang].name}}</div>
                <div :class="['arrow',lanChecked && 'active']"></div>
              </div>
              <a-menu slot="overlay">
                <a-menu-item  v-for="(val,index) in langList" :key="val.lang" @click="langCli(val.lang,index)">
                  <div  class="language-menu-item" >
                    <img :src="val.src" alt="">
                    <span>{{val.name}}</span>
                  </div>
                </a-menu-item>
              </a-menu>
        </a-dropdown>
      </div>
      <template v-if="isPhone">
        <div class="item"  @click="updateVsibleState">
          <div class="line"></div>
          <div class="line"></div>
        </div>
      </template>
    </div>
    <a-drawer
      class="nav-dra"
      width="100%"
      height="100%"
      placement="top"
      :closable="false"
      :visible="menuVisible"
      @close="updateVsibleState"
    >
      <img class="close-btn" @click="updateVsibleState" src="../assets/mobile-icon-closeWhite@2x.png" alt="">
      <div class="menu-wrapper">
        <div class="m-content">
          <div class="menu-item"  @click="$router.push('/mfi')">Metapool</div>  
          <div class="menu-item"  @click="$router.push('/undeveloped')">{{$t('user.M_home_govern')}}</div>  
          <div class="menu-item"  @click="$router.push('/rule')">{{$t('user.M_home_rules')}}</div>  
        </div>
      </div>
      <img class="logo-img" src="../assets/images/logo.png" alt="">
    </a-drawer>
  </div>
</template>

<script>
export default {
  name: 'newNav',
  data () {
    return {
        windowWidth: '-1',
       //语言
        langList:[
          {lang:'en',name:'EN',src:require('../assets/img/en.png')},
          {lang:'ko',name:'KO',src:require('../assets/img/ko.png')},
          {lang:'jp',name:'JA',src:require('../assets/img/jp.png')},
          {lang:'zh',name:'CN',src:require('../assets/img/lang-cn.png')},
          {lang:'es',name:'ES',src:require('../assets/img/es.png')},
        ],
        //选中的语言
        activeLang: 0,
        lanChecked: false,
        menuVisible: false
    }
  },  
  computed:{
    isPhone(){
      if(this.windowWidth == -1) return false
      return this.windowWidth <= 649
    }
  },
  created() {
    this.langList.filter((v,i) => {
      if(localStorage.getItem('languageSet') === v.lang)
      this.activeLang = i
    })
    this.windowWidth = window.innerWidth//浏览器窗口的内部宽度（包括滚动条）
      || document.documentElement.clientWidth
      || document.body.clientWidth;
    window.addEventListener('resize', this.handleResize)
  },
  beforeDestroy(){
    window.removeEventListener('resize', this.handleResize)
  },
  methods: {
    jumpTargetPage(path){
      this.$router.push(path)
    },
    //信息下拉选项
    updateVsibleState() {
      this.menuVisible = !this.menuVisible
    },
    handleResize(e){
      this.windowWidth = window.innerWidth//浏览器窗口的内部宽度（包括滚动条）
      || document.documentElement.clientWidth
      || document.body.clientWidth;
    },
    //语言切换
    langCli(language,index) {
      this.utils.langCli.call(this,language,() => {
        this.activeLang = index;
      })
      this.lanChecked = false

    },
  }
}
</script>

<style scoped lang="scss">
  .nav-dra /deep/ .ant-drawer-content{
    background-color: rgba(0,0,0,.7);
    color: #fff;
  }
  .nav-dra /deep/ .ant-drawer-body{
    >.close-btn{
      position: absolute;
      top: 24px;
      right: 20px;
      width: 40px;
    }
    >.logo-img{
      position: absolute;
      bottom: 70px;
      left: calc(50% - 75px);
      width: 150px;
    }
    >.menu-wrapper{
      width: 100%;
      height: 100%;
      color: #fff;
      position: fixed;
      top: calc(50% - 200px);
    }
  }
  .menu-wrapper {
    position: relative;
    color: #000;
    >.m-content {
      padding: 40px 80px 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      >.close-btn {
        position: absolute;
        right: 20px;
        top: 20px;
        width: 36px;
        height: 36px;
      } 
      >.menu-item {
        position: relative;
        padding: 16px 0;
        text-align: center;
        font-size: 18px;
        font-weight:500;
        >.label{
          display: flex;
          align-items: center;
          justify-content: center;
          img {
            width: 30px;
            height: 20px;
            flex-shrink: 0;
            margin-right: 12px;
          }
        }
      }
    }
  }
  .nav-wrapper {
    width: 100%;
    background: rgba($color: #000, $alpha: .9);
    color: #fff;
    position: fixed;
    display: flex;
    left: 0;
    top: 0;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    >.menu {
      display: flex;
      align-items: center;
    }
    >img{
      cursor: pointer;
    }
    
  }

@media only screen and (min-width: 320px) and (max-width: 639px){
  .nav-wrapper {
    padding: 20px;
    flex-wrap: nowrap;
    
    >img {
      width: 140px;
      flex-shrink: 0;
    }
    >.menu {
      align-items: center;
      >.item {
        >.line {
          margin-left: 20px;
          width: 22px;
          height: 2px;
          background: #fff;
          margin-bottom: 6px;
          &:last-child {
            margin-bottom: 0;
          }
        }
        >.language {
            display: flex;
            align-items: center;
            img {
              width: 22px;
              height: 22px;
              border-radius: 50%;
              flex-shrink: 0;
              margin-right: 8px;
            }
            .arrow {
              width: 8px;
              height: 8px;
              border-top: 1px solid #fff;
              border-right: 1px solid #fff; 
              transform: rotate(135deg);
              transition: all .3s ease;
              margin-left: 10px;
              &.active {
                transform: rotate(-45deg);
              }
            }
          }
      }
    }
  }
  .language-menu-item {
    width: 60px;
    height: 40px;
    display: flex;
    align-items: center;
    img {
      width: 24px;
      height: 24px;
    }
    span {
      padding-left: 12px;
      font-size: 16px;
    }
  }
}

@media only screen and (min-width: 640px) {
  .language-menu-item {
    height: 40px;
    display: flex;
    align-items: center;
    img {
      width: 30px;
      height: 30px;
      margin-right: 3px;
    }
    span {
      font-size: 16px;
    }
  }
    .nav-wrapper {
      padding: 30px 12% 0;
      flex-wrap: wrap;
     
      >img {
        width: 147px;
        flex-shrink: 0;
        margin-right: 10%;
        margin-bottom: 20px;

      }
      >.menu {
        overflow: auto;
        padding-bottom: 20px;

        >.item {
          display: flex;
          align-items: center;
          flex-shrink: 0;
          margin-left: 40px;
          cursor: pointer;

          &:first-child {
            margin-left: 0;
          }
          >.language {
            padding: 2px 20px 2px 10px;
            border-radius: 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: pointer;
            background: rgba($color: #fff, $alpha: .2);
            
            img {
              width: 26px;
              height: 26px;
              border-radius: 50%;
              flex-shrink: 0;
              margin-right: 8px;
            }
            .arrow {
              width: 10px;
              height: 10px;
              border-top: 2px solid #fff;
              border-right: 2px solid #fff; 
              transform: rotate(135deg);
              transition: all .3s ease;
              margin-left: 10px;
              &.active {
                transform: rotate(-45deg);
              }
            }
          }
          >p {
            font-size: 16px;
            color: #fff;
          }
          >.img {
            width: 30px;
            height: 30px;
          }
          >.btn {
            width: 123px;
            height: 43px;
            line-height: 43px;
            text-align: center;
            border: 2px solid #402C97;
            border-radius: 22px;
            font-size: 18px;
          }
        }
      }
    }
}

</style>
